package lagou.homework.lagou_homework_rocketmq.utils;


import lagou.homework.lagou_homework_rocketmq.common.ResponseResult;
import lagou.homework.lagou_homework_rocketmq.exception.SeckillException;

public class Response {

    /**
     * 成功
     * @param message
     * @param data
     * @return
     */
    public static ResponseResult success(String message, Object data){
        return new ResponseResult("200",message,data);
    }

    /**
     * 失败
     * @param e
     * @return
     */
    public static ResponseResult fail(Exception e){
        if(e instanceof SeckillException){
            SeckillException seckillException = (SeckillException) e;
            return new ResponseResult(seckillException.getCode(),seckillException.getMessage(),seckillException.getData());
        }else{
            return new ResponseResult("500","操作失败",e.getMessage());
        }
    }

}
